package cn.pconline.officialclub.entity;

import cn.pconline.autoclub.entity.User;
import cn.pconline.autoclub.util.EncodeUtils;
import com.alibaba.fastjson.JSONObject;
import java.util.Date;
import org.apache.commons.lang.StringUtils;
import org.gelivable.dao.Column;
import org.gelivable.dao.Entity;
import org.gelivable.dao.Id;
import org.gelivable.dao.Transient;

/**
 * 官方车友会
 *
 * @author <a href="mailto:chensy0203@163.com">chensy</a>
 */
@Entity(tableName = "oac_club", logChange = true)
public class OClub extends EntityKit {

    /**
     * 官方车友会ID
     */
    @Id
    @Column(name = "o_club_id")
    private long oClubId;
    /**
     * 名称
     */
    @Column(name = "name")
    private String name;
    /**
     * 车标
     */
    @Column(name = "logo")
    private String logo;
    /**
     * 简介
     */
    @Column(name = "introduce")
    private String introduce;
    /**
     * 车友会个性域名
     */
    @Column(name = "url")
    private String url;
    /**
     * 状态,0非认证，1认证
     */
    @Column(name = "cover_image")
    private String coverImage;
    /**
     * 认证人数
     */
    @Column(name = "vip_num")
    private int vipNum;
    /**
     * 入驻车友会个数
     */
    @Column(name = "club_num")
    private int clubNum;
    /**
     * 会员人数
     */
    @Column(name = "member_num")
    private int memberNum;
    /**
     * 论坛版块Id
     */
    @Column(name = "forum_id")
    private long forumId;
    /**
     * 分类标签Id
     */
    @Column(name = "tag_id")
    private long tagId;
    /**
     * 所属地址分区Id
     */
    @Column(name = "region_id")
    private long regionId;
    /**
     * 所属地址分区
     */
    @Column(name = "region_name")
    private String regionName;
    /**
     * 所属省份Id
     */
    @Column(name = "province_id")
    private long provinceId;
    /**
     * 所属省份
     */
    @Column(name = "province_name")
    private String provinceName;
    /**
     * 所属城市Id
     */
    @Column(name = "city_id")
    private long cityId;
    /**
     * 所属城市
     */
    @Column(name = "city_name")
    private String cityName;
    /**
     * 品牌ID
     */
    @Column(name = "brand_id")
    private long brandId;
    /**
     * 品牌名称
     */
    @Column(name = "brand_name")
    private String brandName;
    /**
     * 车系ID
     */
    @Column(name = "series_id")
    private long seriesId;
    /**
     * 车系名称
     */
    @Column(name = "series_name")
    private String seriesName;
    /**
     * 创建时间
     */
    @Column(name = "create_at")
    private Date createAt;
    /**
     * 创建者
     */
    @Column(name = "create_by")
    private long createBy;
    /**
     * 更新时间
     */
    @Column(name = "update_at")
    private Date updateAt;
    /**
     * 更新者
     */
    @Column(name = "update_by")
    private long updateBy;
    /**
     * 状态
     */
    @Column(name = "status")
    private int status;
    
    /**
     * 是否需要绑定手机
     */
    @Column(name="bind_phone")
    private int bindPhone;
    
    public static final int STATUS_UNRELEASED = 0; //未发布
    public static final int STATUS_NORMAL = 1; //正常
    public static final int STATUS_ALL = -1;//所有
    public static final String LOGO_DEF_PC = "http://www1.pcauto.com.cn/2014/club/v4_1/common/defaultphoto2_150x150.jpg";
    public static final String LOGO_DEF = "http://www1.pcauto.com.cn/bbs/cargroup/2014/images/defaultphoto2.png";
    public static final int MAX_INTRODUCE_LENGTH = 255;//简介最大长度
    public static final int MAX_REMARK_LENGTH = 255;//备注最大长度]
    /**
     * 需要绑定手机 
     */
    public static final int BIND_PHONE = 1;
    /**
     * 不需要绑定手机
     */
    public static final int NOT_BIND_PHONE = 0;
    
    @Transient(cache = false)
    private User creator;
    /**
     * 车友会所属分类
     */
    @Transient(cache=false)
    private OClubTag tag;
    public long getoClubId() {
        return oClubId;
    }

    public void setoClubId(long oClubId) {
        this.oClubId = oClubId;
    }

    /**
     * 兼容geli
     *
     * @return
     */
    public long getOClubId() {
        return oClubId;
    }

    /**
     * 兼容geli
     *
     * @return
     */
    /**
     * 兼容geli
     *
     * @return
     */
    public void setOClubId(long oClubId) {
        this.oClubId = oClubId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public String getIntroduce() {
        return introduce;
    }

    public void setIntroduce(String introduce) {
        this.introduce = introduce;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getCoverImage() {
        return coverImage;
    }

    public void setCoverImage(String coverImage) {
        this.coverImage = coverImage;
    }

    public String getCoverImage280x140() {
        return convertImage(coverImage, "280x140");
    }

    public String getCoverImage990x250() {
        return convertImage(coverImage, "990x250");
    }
     public String getCoverImage640x160() {
        return convertImage(coverImage, "640x160");
    }
    public int getVipNum() {
        return vipNum;
    }

    public void setVipNum(int vipNum) {
        this.vipNum = vipNum;
    }

    public int getClubNum() {
        return clubNum;
    }

    public void setClubNum(int clubNum) {
        this.clubNum = clubNum;
    }

    public int getMemberNum() {
        return memberNum;
    }

    public void setMemberNum(int memberNum) {
        this.memberNum = memberNum;
    }

    public long getForumId() {
        return forumId;
    }

    public void setForumId(long forumId) {
        this.forumId = forumId;
    }

    public long getTagId() {
        return tagId;
    }

    public void setTagId(long tagId) {
        this.tagId = tagId;
    }

    public long getRegionId() {
        return regionId;
    }

    public void setRegionId(long regionId) {
        this.regionId = regionId;
    }

    public String getRegionName() {
        return regionName;
    }

    public void setRegionName(String regionName) {
        this.regionName = regionName;
    }

    public long getProvinceId() {
        return provinceId;
    }

    public void setProvinceId(long provinceId) {
        this.provinceId = provinceId;
    }

    public String getProvinceName() {
        return provinceName;
    }

    public void setProvinceName(String provinceName) {
        this.provinceName = provinceName;
    }

    public long getCityId() {
        return cityId;
    }

    public void setCityId(long cityId) {
        this.cityId = cityId;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public long getBrandId() {
        return brandId;
    }

    public void setBrandId(long brandId) {
        this.brandId = brandId;
    }

    public String getBrandName() {
        return brandName;
    }

    public void setBrandName(String brandName) {
        this.brandName = brandName;
    }

    public long getSeriesId() {
        return seriesId;
    }

    public void setSeriesId(long seriesId) {
        this.seriesId = seriesId;
    }

    public String getSeriesName() {
        return seriesName;
    }

    public void setSeriesName(String seriesName) {
        this.seriesName = seriesName;
    }

    public Date getCreateAt() {
        return createAt;
    }

    public void setCreateAt(Date createAt) {
        this.createAt = createAt;
    }

    public long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(long createBy) {
        this.createBy = createBy;
    }

    public Date getUpdateAt() {
        return updateAt;
    }

    public void setUpdateAt(Date updateAt) {
        this.updateAt = updateAt;
    }

    public long getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(long updateBy) {
        this.updateBy = updateBy;
    }

    public User getCreator() {
        return creator;
    }

    public void setCreator(User creator) {
        this.creator = creator;
    }

    public String converLogo(String size) {
        if (StringUtils.isBlank(logo)) {
            return LOGO_DEF;
        }
        return logo.replace(".jpg", "_" + size + ".jpg");
    }

    public String getLogo150x150() {
        if (StringUtils.isBlank(logo)) {
            return LOGO_DEF_PC;
        }

        return converLogo("150x150");
    }
     public String getLogo135x100() {
        if (StringUtils.isBlank(logo)) {
            return LOGO_DEF_PC;
        }

        return converLogo("135x100");
    }
    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public boolean isHasLogo() {
        if (OClub.LOGO_DEF_PC.equals(getLogo())) {
            return false;
        }
        if (OClub.LOGO_DEF.equals(getLogo())) {
            return false;
        }
        return true;
    }

    public OClubTag getTag() {
        return tag;
    }

    public void setTag(OClubTag tag) {
        this.tag = tag;
    }

    public int getBindPhone() {
        return bindPhone;
    }

    public void setBindPhone(int bindPhone) {
        this.bindPhone = bindPhone;
    }
    
    public boolean isMustBindPhone(){
        return bindPhone == BIND_PHONE;
    }
 
    /**
     * 返回可见公共信息JSON格式
     *
     * @param isEncode
     * @return
     */
    public JSONObject getJSON(boolean isEncode) {
        JSONObject o = new JSONObject();
        o.put("oClubId", oClubId);
        o.put("name", EncodeUtils.encodeForHTML(name, isEncode));
        o.put("introduce", EncodeUtils.encodeForHTML(introduce, isEncode));
        o.put("logo", logo);
        o.put("logo135x100",getLogo135x100());
        o.put("logo150x150",getLogo150x150());
        o.put("url", EncodeUtils.encodeForHTML(url, isEncode));
        o.put("brandId", brandId);
        o.put("brandName", EncodeUtils.encodeForHTML(brandName, isEncode));
        o.put("seriesId", seriesId);
        o.put("seriesName", EncodeUtils.encodeForHTML(seriesName, isEncode));
        o.put("regionId", regionId);
        o.put("regionName", EncodeUtils.encodeForHTML(regionName, isEncode));
        o.put("provinceId", provinceId);
        o.put("provinceName", EncodeUtils.encodeForHTML(provinceName, isEncode));
        o.put("provinceId", cityId);
        o.put("cityName", EncodeUtils.encodeForHTML(cityName, isEncode));
        o.put("clubNum", clubNum);
        o.put("vipNum", vipNum);
        o.put("tagId", tagId);
        o.put("forumId", forumId);
        o.put("memberNum", memberNum);
        o.put("createAt", createAt.getTime());
        return o;
    }
}
